package logic

import (
	"context"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ComListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewComListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ComListLogic {
	return &ComListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ComListLogic) ComList(in *tiebarpc.ComListRequest) (*tiebarpc.ComListResponse, error) {
	// todo: add your logic here and delete this line
	var com []mysql.Comment
	mysql.DB.Debug().Find(&com)
	var b []*tiebarpc.ComList
	for _, c := range com {
		list := tiebarpc.ComList{
			ComId:   int64(c.ID),
			TieZiId: int64(c.TieZiId),
			UserId:  int64(c.UserId),
			Content: c.Content,
		}
		b = append(b, &list)
	}
	return &tiebarpc.ComListResponse{List: b}, nil
}
